package cn.springcloud.fix.auth.controller;

import cn.springcloud.fix.common.core.base.R;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @GetMapping("/admin/hello")
    public R<Object> admin() {
        return R.SUCCESS("hello admin!");
    }

    @GetMapping("/user/hello")
    public R<Object> user() {
        return R.SUCCESS("hello user!");
    }

    @GetMapping("/db/hello")
    public R<Object> dba() {
        return R.SUCCESS("hello dba!");
    }

    @GetMapping("/hello")
    public R<Object> hello() {
        return R.SUCCESS("hello!");
    }

    @GetMapping("/product/{id}")
    public String getProduct(@PathVariable String id) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "product id : " + id;
    }

    @GetMapping("/order/{id}")
    public String getOrder(@PathVariable String id) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "order id : " + id;
    }
}
